# frozen_string_literal: true

# == Schema Information
#
# Table name: roles
#
#  id          :bigint(8)        not null, primary key
#  name        :string(255)      not null
#  permissions :text(65535)
#  type        :string(255)      not null
#  created_at  :datetime         not null
#  updated_at  :datetime         not null
#


class Role < RoleCore::Role
  # has_many :admin_users
  has_many :role_assignments, dependent: :destroy
  # 通过assign获取角色的用户
  has_many :admin_users, through: :role_assignments

  # 数据库绑定
  # has_many :permission_assigments, dependent: :destroy
  # has_many :permissions, through: :permission_assigments

  def permissions_arr
    arr = []
    permissions.to_h.to_a.array.each do |key,val|
      tmp=[index=>val.reduce { |val| val }]
      arr<<tmp
    end
    arr
  end

  def permissions_line

  end

end
